/*
 * graph2D
 * Copyright (c) 2011 Shun Moriya <shun@mnu.sakura.ne.jp>
 *
 * The MIT License
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#if !defined(___GRAPHC2D_MESSAGE_WINDOW_H___)
#define ___GRAPHC2D_MESSAGE_WINDOW_H___

#if !defined(___GRAPH2D_STATIC_CONTAINER_H___)
#include "staticContainer.h"
#endif

#if !defined(___GRAPHC2D_MESSAGE_H___)
#include "message.h"
#endif

#if !defined(___GRAPH2D_WINDOW_H___)
#include "window.h"
#endif

#include <cstdarg>

namespace Graph2D
{
	typedef StaticContainer<1> MessageWindowContainer;

	class MessageWindow : public Window<MessageWindowContainer>
	{
		DISALLOW_COPY_AND_ASSIGN(MessageWindow);

		typedef Window<MessageWindowContainer> super;

	public:
		MessageWindow()
		{
			setType(TYPE_MESSAGE_WINDOW);

			set(0, message);

			setSize(480.0f, 96.0f);
			setColor(0.2f, 0.2f, 1.0f, 1.0f, 0.0f);
			setFrameStyle(FRAME_STYLE_NORMAL);
		}

		virtual ~MessageWindow()
		{
			clear();
		}

		virtual const char* getTypeName() const
		{
			return "MessageWindow";
		}

		void clear()
		{
			message.clear();
		}

		const std::string& getString() const
		{
			return message.getString();
		}

		void setString(const std::string& text)
		{
			message.setString(text);
		}

		void replace(const char* key, const char* word)
		{
			message.replace(key, word);
		}

		Message& getMessage()
		{
			return message;
		}

		const Message& getMessage() const
		{
			return message;
		}

		void format(const char* format, ...)
		{
			va_list ap;
			va_start(ap, format);
			message.vformat(format, ap);
			va_end(ap);
		}

		void vformat(const char* format, va_list ap)
		{
			message.vformat(format, ap);
		}

		const Color& getTextColor() const
		{
			return message.getTextColor();
		}

		void setTextColor(const Color& color)
		{
			message.setTextColor(color);
		}

		void setTextColor(const float r, const float g, const float b, const float a)
		{
			setTextColor(Color(r, g, b, a));
		}

		float getTimer() const
		{
			return message.getTimer();
		}

		void setTimer(const float timer)
		{
			message.setTimer(timer);
		}

		float getDelayTimer() const
		{
			return message.getDelayTimer();
		}

		void setDelayTimer(const float delayTimer)
		{
			message.setDelayTimer(delayTimer);
		}

		bool finished() const
		{
			return message.finished();
		}

		virtual void onSizeChanged()
		{
			message.setPosition(0, 0);
			message.setSize(getClientSize());
		}

	private:
		Message message;
	};
}

#endif
